package panel.viewSpots.navigation
{
	import assists.HtmlText;
	import assists.Lang;
	import assists.TextFieldUtils;
	import assists.media.SoundMedia;
	import assists.resource.ResourceLoader;
	
	import com.greensock.TweenLite;
	
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import main.ClientConstants;
	
	public class NavigationBtnGroup extends Sprite
	{
		private var _loader:ResourceLoader;
		private var _lang:Lang;
		private var _plusBtn:Sprite;
		private var _minBtn:Sprite;
		private var _navigationBtn:Sprite;
		private var _changeScaleFunc:Function;
		private var _navigationFunc:Function;
		private var _stage:Stage;
		private var _backBtn:Sprite;
		private var _musicBtn:Sprite;
		private var _menuUp:NavigationMenuUp;
		private var _menuDown:NavigationMenuDown;
		private var _moveType:int//标示菜单移动方式
		private static const MOVE_UP_DOWN:int = 1;
		private static const MOVE_UP_UP:int = 2;
		private static const MOVE_DOWN_UP:int = 3;
		private static const MOVE_DOWN_DOWN:int = 4;
		private static const MOVE_SPEED:Number = 0.6;
		private var _moveLock:Boolean;
		private var _downGroup:Sprite;
		private var _upGroup:Sprite;
		private var _scrollTxtGroup:Sprite;

		private var _scrollTxt:ScrollTxtHor;
		public function NavigationBtnGroup(loader:ResourceLoader,stage:Stage,lang:Lang)
		{
			_loader = loader;
			_stage = stage;
			_lang = lang;
			super();
		}
		
		public function init(changeScaleFunc:Function,searchFunc:Function,navigationFunc:Function,weiboFunc:Function,changeArrowVisible:Function,showWc:Function):void
		{
			
			_plusBtn = new Sprite();
			_minBtn = new Sprite();
			_navigationBtn = new Sprite();
			_backBtn = new Sprite();
			_musicBtn = new Sprite();
			_menuDown = new NavigationMenuDown(_loader,_stage,_lang);
			_menuDown.onFuncs(searchFunc,weiboFunc,changeArrowVisible,showWc);
			_upGroup = new Sprite();
			_downGroup = new Sprite();
			_scrollTxtGroup = new Sprite();
		
			_plusBtn.addChild(_loader.uiManager.generateBmp(_loader.uiManager.jiaPng));
			_minBtn.addChild(_loader.uiManager.generateBmp(_loader.uiManager.jianPng));
			_navigationBtn.addChild(new _loader.uiManager.navigationPng());
			_backBtn.addChild(_loader.uiManager.generateBmp(_loader.uiManager.backPng));
			_musicBtn.addChild(_loader.uiManager.generateBmp(_loader.uiManager.musicPng));
			
			_plusBtn.addEventListener(MouseEvent.CLICK,clickPlusHandler);
			_minBtn.addEventListener(MouseEvent.CLICK,minHandler);
			_navigationBtn.addEventListener(MouseEvent.CLICK,clickNavigationHandler);
			_backBtn.addEventListener(MouseEvent.CLICK,backHandler);
			_musicBtn.addEventListener(MouseEvent.CLICK,musicHandler);
			
			_changeScaleFunc = changeScaleFunc;
			_navigationFunc = navigationFunc;
			
			_menuDown.y = _stage.stageHeight;
			
			
			_musicBtn.filters = [ClientConstants.GLOBAL_FILTER_GREY];
			_musicBtn.mouseEnabled = false;
			
			_scrollTxt = new ScrollTxtHor();
			_scrollTxt.showWid = _stage.stageWidth;
			_scrollTxt.label("欢迎您来荣成旅游",0xfff100);
			_scrollTxtGroup.graphics.beginFill(0,0.8);
			_scrollTxtGroup.graphics.drawRect(0,0,_stage.stageWidth,_scrollTxt.height);
			_scrollTxtGroup.graphics.endFill();
			_scrollTxtGroup.addChild(_scrollTxt);
			_musicBtn.y = _scrollTxtGroup.y + _scrollTxtGroup.height;
			
			resize();
			this.addChild(_upGroup);
			this.addChild(_downGroup);
			_downGroup.addChild(_plusBtn);
			_downGroup.addChild(_minBtn);
			_downGroup.addChild(_navigationBtn);
			_downGroup.addChild(_backBtn);
			_downGroup.addChild(_menuDown);
			_upGroup.addChild(_musicBtn);
			_upGroup.addChild(_scrollTxtGroup);
		}
		
		public function set onSoundMedia(value:SoundMedia):void
		{
			_musicBtn.filters = [];
			_musicBtn.mouseEnabled = true;
			_menuUp = new NavigationMenuUp(_stage,_loader,value);
			_menuUp.y = - _menuUp.height;
			_upGroup.addChild(_menuUp);
		}
		
		protected function musicHandler(event:MouseEvent):void
		{
			trace("music");
			if(!_menuUp) return;
			if(_moveType == MOVE_UP_DOWN)
			{
				moveMenu(MOVE_UP_UP);
			}else
			{
				moveMenu(MOVE_UP_DOWN);
			}
		}
		
		private function moveMenu(type:int):void
		{
			if(_moveLock) return;
			_moveLock = true;
			_moveType = type;
			moveMenuHandler();
		}
		
		private function tweenLiteEnd():void
		{
			_moveLock = false;
		}
		
		protected function moveMenuHandler():void
		{
			
			if(_moveType == MOVE_UP_DOWN)
			{
				TweenLite.to(_upGroup,MOVE_SPEED,{y: _menuUp.height,onComplete:tweenLiteEnd});
			}else if(_moveType == MOVE_UP_UP)
			{
				TweenLite.to(_upGroup,MOVE_SPEED,{y: 0,onComplete:tweenLiteEnd});
			}else if(_moveType == MOVE_DOWN_UP)
			{
				TweenLite.to(_downGroup,MOVE_SPEED,{y: - _menuDown.height,onComplete:tweenLiteEnd});
			}else if(_moveType == MOVE_DOWN_DOWN)
			{
				TweenLite.to(_downGroup,MOVE_SPEED,{y:0,onComplete:tweenLiteEnd});
			}
			
			
		}
		
		public function update(spotName:String,costTime:Number):void
		{
			if(costTime == 0)
			{
				_scrollTxt.label( spotName);
			}else
			{
				
			_scrollTxt.label("上次游览位置：" + spotName + "     游览完成百分比(时间)：" + costTime * 100 + "%");
			}
			
		}
		
		private function addZeroStr(value:Number):String
		{
			if(value < 10)
			{
				return "0" + value;
			}else
			{
				return value + "";
			}
		}
		
		protected function backHandler(event:MouseEvent):void
		{
			if(_moveType == MOVE_DOWN_UP)
			{
				moveMenu(MOVE_DOWN_DOWN);
			}else
			{
				moveMenu(MOVE_DOWN_UP);
			}
		}
		
		private function resize():void
		{
			_backBtn.x = _stage.stageWidth * 0.05;
			_backBtn.y = _stage.stageHeight * 0.95 - _backBtn.height;
			
			_minBtn.y = _backBtn.y;
			_minBtn.x = _stage.stageWidth * 0.95 - _minBtn.width ;
			
			_plusBtn.x = _minBtn.x;
			_plusBtn.y = _minBtn.y - _plusBtn.height - _stage.stageHeight * 0.05
				
			_navigationBtn.x = _backBtn.x;
			_navigationBtn.y = _backBtn.y - _backBtn.height - _stage.stageHeight * 0.05
		}
		
		protected function clickNavigationHandler(event:MouseEvent):void
		{
			_navigationFunc();
		}
		
		protected function minHandler(event:MouseEvent):void
		{
			_changeScaleFunc(2);
		}

		protected function clickPlusHandler(event:MouseEvent):void
		{
			_changeScaleFunc(1);
		}		
		
		
	}
}